<?php

header("Content-type: text/xml\n\n");
echo ( '<?xml version="1.0"?>' . "\n");
?>


<?php

session_start();

include '../datos/AccesoDatos.php';
include 'session.php';
include_once ('sqlinjection.php');
if (isset($_GET['accion'])) {
    $accion = $_GET['accion'];
}



$objSeguridad = new Seguridad();
switch ($accion) {

    case "perfilusuario": $objSeguridad->ListarPerfilUsuarios();
        break;
   
}

class Seguridad {

    public function ListarPerfilUsuarios() {


        $page = $_GET['page'];

// get how many rows we want to have into the grid - rowNum parameter in the grid 
        $limit = $_GET['rows'];

// get index row - i.e. user click to sort. At first time sortname parameter -
// after that the index from colModel 
        $sidx = $_GET['sidx'];

// sorting order - at first time sortorder 
        $sord = $_GET['sord'];

        $centromedico = $_GET['centromedico'];


        // $this->idpersona = $_GET['idpersona'];

        $sql = "Select * from adm_perfiles where id_personajuridica = '" . $centromedico . "'";
        $objDatos = new AccesoDatos();
        $objDatos->ejecutarConsultaSencilla($sql);
        $error = $objDatos->devuelveError();

        $count = $objDatos->devuelveRegsLeidos();
        // calculate the total pages for the query 
        if ($count > 0 && $limit > 0) {
            $total_pages = ceil($count / $limit);
        } else {
            $total_pages = 0;
        }

// if for some reasons the requested page is greater than the total 
// set the requested page to total page 
        if ($page > $total_pages)
            $page = $total_pages;

// calculate the starting position of the rows 
        $start = $limit * $page - $limit;

// if for some reasons start position is negative set it to 0 
// typical case is that the user type 0 for the requested page 
        if ($start < 0)
            $start = 0;

        $s = '<rows>';
        $s .='<page>' . $page . '</page>';
        $s .= '<total>' . $total_pages . "</total>";
        $s .='<records>' . $count . '</records>';

        $cont = 0;

        while ($row = $objDatos->devuelveArreglo()) {

            if ($cont >= $start) {
                $s .= '<row id="' . $row['ID_PERFIL'] . '">';
                $s .= '<cell><![CDATA[' . $row['DS_PERFILUSUARIO'] . ']]></cell>';

                $s .= '</row>';
            }

            $cont++;
        }
        $s .='</rows>';
        echo $s;
    }


}
?>

